//获取用户信息
function getUserinfo() {
  $.ajax({
    type: "GET",
    url: "/my/user/userinfo",
    success: function (res) {
        if(res.data.nickname){
            let nickfirst = res.data.nickname.slice(0, 1).toUpperCase();
            $(".headImg").text(nickfirst);
            $("#user").text(res.data.nickname);
        }else{
            let first = res.data.username.slice(0, 1).toUpperCase();
            $(".headImg").text(first);
            $("#user").text(res.data.username);
        }
      if (res.data.user_pic) {
        $(".head").attr("src", res.data.user_pic).css("display", "inline-block");
        $(".headImg").css("display", "none");
      } else{
        $(".headImg").css("display", "inline-block");
        $(".head").css("display", "none");
      } 
    },
  });
}
getUserinfo();

// 退出功能
$("#logout").on("click", function () {
  layer.confirm("确认退出吗？", { icon: 3, title: "提示" }, function (index) {
    localStorage.removeItem("token"); //清除缓存
    location.href = "./login.html"; //跳转页面
    layer.close(index); // 关闭
  });
});
